package Car;

/**
 * @author chenjian
 * @version 1.0
 * @date 2025/3/20 19:46
 * @description
 */

/*2、建立一个汽车 Auto 类，包括轮胎个数，汽车颜色，车身重量、速度等成员变量。
        并通过不同的构造方法创建实例。至少要求： 汽车能够加速，减速，停车。 再
        定义一个小汽车类 Car，继承 Auto，并添加空调、CD 等成员变量，覆盖加速，
        减速的方法、class Auto*/

    /*
    * 1.先写一个父类Auto,属性：轮胎个数，汽车颜色，车身重量、速度
    *                   方法：加速，减速，停车
    *
    * 其中的满参构造方法，写两个，一个正常满参，一个速度为0；
    *
    * 成员方法无论加速还是减速都有参考值，所以要有参
    *
    * */


public class Auto {
    //成员变量
    protected  int tirecount;
    protected  String color;
    protected  double weight;
    protected  double speed;

    public Auto() {
    }

    //两个构造方法

    //正常满参
    public Auto(int tirecount, String color, double weight, double speed) {
        this.tirecount = tirecount;
        this.color = color;
        this.weight = weight;
        this.speed = speed;
    }

    //速度为0时,的满参构造方法

    public Auto(int tirecount, String color, double weight) {
        this.tirecount = tirecount;
        this.color = color;
        this.weight = weight;
        this.speed=0;
    }

    public int getTirecount() {
        return tirecount;
    }

    public void setTirecount(int tirecount) {
        this.tirecount = tirecount;
    }

    public String getColor() {
        return color;
    }

    public void setColor(String color) {
        this.color = color;
    }

    public double getWeight() {
        return weight;
    }

    public void setWeight(double weight) {
        this.weight = weight;
    }

    public double getSpeed() {
        return speed;
    }

    public void setSpeed(double speed) {
        this.speed = speed;
    }

    //加速
    public void addspeed(double value){
        this.speed+=value;
        System.out.println("汽车加速，当前速度: " + this.speed);
    }

    //减速
    public void slowspeed(double value){
        //先判定
        if (this.speed - value < 0) {
            this.speed = 0;
        } else {
            this.speed -= value;
        }
        System.out.println("汽车减速，当前速度: " + this.speed);

    }

    //停止
    public void stop(){
        this.speed=0;
        System.out.println("汽车停车，当前速度: 0");
        }

}
